
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

	<!--<f:loadBundle basename="resources.application" var="msg"/>-->

	<head>
	    <title>NaMaoList</title>
		<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.4.2/pure-min.css"/>
		<style>
			* {
				font-family: /*"Segoe UI Semibold", "Segoe UI Web Semibold",*/
				"Segoe UI Web Regular", "Segoe UI", "Segoe UI Symbol",
				"HelveticaNeue-Medium", "Helvetica Neue", Arial, sans-serif;
			}
			input{
				height: 20px;
			}
			.FieldSet {
				border-bottom: 1px solid #e5e5e5;
			}
			.FieldSetItem{
				border-bottom: none;
			}
			.FieldSetPanelGroup {
				margin-left: 20px;
				margin-right: 40px;
				border-bottom: 1px solid #e5e5e5;
			}
			.FieldSetPanelGroupItem {
				border-bottom: none;
				margin-left: 0;
			}
			.LegendFieldSet{
				font-size: 110%;
			}
			.LegendFieldSetPanelGroup {
				font-size: 100%;
			}
			.Table {
				width: 100%;
				padding-bottom: 2px; 
			}
			label {
				font-size: 90%;
			}
			.CommandButton {
				font-size: 80%;
 				padding-bottom: 20px; 
 				margin-bottom: 2px;
			}
			span {
				font-size: 90%;
				display: block;
				margin: .25em 0;
			}
			.Optional {}
			.Entry {}
		</style>
		<script>
			//<![CDATA[
			function validate(event){
				var elements = document.getElementsByClassName('Entry');
				if(elements != null){
					for(var index = 0; index < elements.length; index++){
						var element = elements[index];
						var hasOptionalClass = element.className.indexOf('Optional') >= 0;
						var isInputText = element.nodeName == 'INPUT';
						var isSelect = element.nodeName == 'SELECT';
						var isEmpty = element.value == '';
						if((isInputText || isSelect) && !hasOptionalClass && isEmpty){
							alert('Preencha os campos obrigat\u00f3rios');
							return false;
						}
					}
					return true;
				}
			}
			function doTransition(event, callType, noReturn){
				var isValid = validate();
				if(!isValid){
					event.returnValue = false;
					return false;
				}
				if(!noReturn){
					if(callType == 'other'){
						var uidCall = sessionStorage.getItem("uidCall");
						if(uidCall == null){
							uidCall = "";
						}
						uidCall = uidCall.split(",");
						uidCall[uidCall.length] = "namaolist.xhtml";
						sessionStorage.setItem("uidCall", uidCall);
					}else{
						var stateCall = sessionStorage.getItem("stateCall");
						if(stateCall == null){
							stateCall = "";
						}
						stateCall = stateCall.split(",");
						stateCall[stateCall.length] = "namaolist.xhtml";
						sessionStorage.setItem("stateCall", stateCall);
					}
				}
				event.returnValue = true;
				return true;
			}
			window.onload = function(){
				var history = sessionStorage.getItem("history");
				if(history == null){
					history = "";
				}
				history = history.split(",");
				if(history[history.length -1 ] == "namaolist.xhtml"){
					history.splice(history.length -1, 1);
				}else{
					history[history.length] = "namaolist.xhtml";
				}
				sessionStorage.setItem("history", history);

				var uidCallArray = sessionStorage.getItem("uidCall");
				var stateCallArray = sessionStorage.getItem("stateCall");
				
				if(uidCallArray != null && uidCallArray != ""){
					uidCallArray = uidCallArray.split(",");
					if(uidCallArray[uidCallArray.length -1] == "namaolist.xhtml"){
						uidCallArray.splice(uidCallArray.length -1, 1);
						sessionStorage.setItem("uidCall", uidCallArray);
					}
				}

				if(stateCallArray != null && stateCallArray != ""){
					stateCallArray = stateCallArray.split(",");
					if(stateCallArray[stateCallArray.length -1] == "namaolist.xhtml"){
						stateCallArray.splice(stateCallArray.length -1, 1);
						sessionStorage.setItem("stateCall", stateCallArray);
					}
				}

				var isLeefState = document.getElementsByClassName("CommandButton").length == 2;

				if(isLeefState && uidCallArray != null && uidCallArray != ""){
					var uidCall = uidCallArray[uidCallArray.length -1];
					if(uidCall != null && uidCall != ""){
						var uidCallButton = document.getElementById('uidCallButton');
						uidCallButton.parentNode.style.visibility = 'visible';
						uidCallButton.style.visibility = 'visible';
						uidCallButton.onclick = function(){
							sessionStorage.setItem("uidCall", "");
							var history = sessionStorage.getItem("history").split(",");
							var indexToGo = 0;
							for(var index = history.length - 1; index >= 0; index--){
								if(history[index] == uidCall){
									history.splice(history.length - 1, indexToGo);
									sessionStorage.setItem("history", history);
									uidCallArray.splice(uidCallArray.length - 1, 1);
									sessionStorage.setItem("uidCall", uidCallArray);
									var stateCallArray = sessionStorage.getItem("stateCall").split(",");
									stateCallArray.splice(stateCallArray.length - 1, indexToGo);
									sessionStorage.setItem("stateCall", stateCallArray);
									window.history.go(-indexToGo);
									return true;
								}
								indexToGo += 1;
							}
						};
					}
				}

				if(stateCallArray != null && stateCallArray != ""){
					var stateCall = stateCallArray[stateCallArray.length -1];
					if(stateCall != null && stateCall != ""){
						var stateCallButton = document.getElementById('stateCallButton');
						stateCallButton.parentNode.style.visibility = 'visible';
						stateCallButton.style.visibility = 'visible';
						stateCallButton.onclick = function(){
							sessionStorage.setItem("stateCall", "");
							var history = sessionStorage.getItem("history").split(",");
							var indexToGo = 0;
							for(var index = history.length - 1; index >= 0; index--){
								if(history[index] == stateCall){
									history.splice(history.length - 1, indexToGo);
									sessionStorage.setItem("history", history);
									stateCallArray.splice(stateCallArray.length - 1, 1);
									sessionStorage.setItem("stateCall", stateCallArray);
									window.history.go(-indexToGo);
									return true;
								}
								indexToGo += 1;
							}
						};
					}
				}
			};
			//]]>
		</script>
	</head>
	<body>
		<h:form class="pure-form pure-form-stacked" style="max-width: 600px; padding:20px;" >
		<!--<div style="font-size:200%; padding-bottom:20px;" >NaMaoList</div>-->
		<div class="pure-g-r">
			<div class="pure-u-1-2">
			<h:outputLabel >&nbsp;</h:outputLabel>
			<h:commandButton class="pure-button pure-button-primary CommandButton" value="Add" action="namaoadd?faces-redirect=true" onclick="doTransition(event, 'other', false)"></h:commandButton>
			</div>
			<div class="pure-u-1 ">
			<h:panelGroup >
			<fieldset class="pure-u-1 " >
			<div class="pure-g-r FieldSet">
			<legend class="pure-u-1 LegendFieldSet" >NaMaoAttribute1</legend>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute1</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute2</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute3</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute4</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute5</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute6</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute7</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute8</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute9</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
				<div class="pure-u-1-2 FieldSetItem">
				<h:outputLabel >NaMaoAttribute10</h:outputLabel>
				</div>
					<div class="pure-u-1-2">
						<h:outputLabel >&nbsp;</h:outputLabel>
					<h:commandButton class="pure-button pure-button-primary CommandButton" value="Edit" action="namaoedit?faces-redirect=true" onclick="doTransition(event, 'other')"></h:commandButton>
					</div>
			</div>
			</fieldset>
			</h:panelGroup>
			</div>
			<div class="pure-u-1-1"  >
				<h:outputLabel >&nbsp;</h:outputLabel>
			</div>
			<div class="pure-u-1-2" style='visibility: hidden;' >
				<input id="stateCallButton" type='button' class='pure-button pure-button-primary CommandButton' style='visibility: hidden;' value='Retornar ao estado anterior' onclick='' />
			</div>
			<div class="pure-u-1-2" style='visibility: hidden;' >
				<input id="uidCallButton" type='button' class='pure-button pure-button-primary CommandButton' style='visibility: hidden;' value='Retornar ao UID anterior' onclick='' />
			</div>
		</div>
		</h:form>
	</body>
</html>
